<template>
  <div class="photoList">
    <van-tabs animated>
      <van-tab
        v-for="el in list"
        :key="el.id"
        :title="el.title"
      >
        <template #title>
          <div @click="getImg(el.id)">
            {{el.title}}
          </div>
        </template>
        <div
          class="img-box"
          v-if="images.length>0"
        >
          <img
            v-for="el in images"
            :key="el.id"
            v-lazy="el.img_url"
            @click=" getdetail(el.id)"
          >
        </div>
        <div v-else>
          暂无数据
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>
<script>
import { getphotoList, getImg } from '../../../api/home'
export default {
  data: () => ({
    list: [],
    images: []
  }),
  created() {
    this.getPhoto()
    this.getImg(0)
  },
  methods: {
    async getPhoto() {
      console.log(111)
      const res = await getphotoList()
      res.data.message.unshift({
        id: 0,
        title: '全部'
      })
      this.list = res.data.message
    },
    async getImg(id) {
      const res = await getImg(id)
      this.images = res.data.message
    },
    getdetail(id) {
      this.$router.push('/home/photoList/' + id)
    }
  }
}
</script>
<style lang="less" >
.photoList {
  .img-box {
    padding: 5px 5px;
    img {
      width: 100%;
    }
  }
}
</style>